package com.yznote.cloudesk.common.utils;

import com.github.yitter.contract.IdGeneratorOptions;
import com.github.yitter.idgen.YitIdHelper;
import com.yznote.cloudesk.common.constants.YConstant;
import com.yznote.cloudesk.common.pojo.User;

import java.util.regex.Pattern;

public class IdUtils {
    static {
        IdGeneratorOptions options = new IdGeneratorOptions((short) 1);
        YitIdHelper.setIdGenerator(options);
    }

    /**
     * 生成id
     *
     * @return
     */
    public static Long nextId() {
        return YitIdHelper.nextId();
    }
    /**
     * 注册判断用户格式
     *
     * @param user
     * @return
     */
    public static String verifyUser(User user) {
        String userName = user.getUserName();
        // 4-7 个字符 字母开头 只准有字母数字
        if (!Pattern.matches("^[a-zA-Z]{1}[a-zA-Z0-9]{3,6}$", userName)) {
            return YConstant.ERROR_USERFORMATEXC;
        }
        if (user.getPassword().length() < 6) {
            return YConstant.ERROR_PWDFORMATEXC;
        }
//        String phoneNum = user.getPhonenumber();
//        if (!Pattern.matches("^[1]{1}[3457]{1}[0-9]{9}$", phoneNum)) {
//            return "手机号格式错误";
//        }
//        String email = user.getEmail();
////        if (!Pattern.matches("^[0-9a-zA-Z]+@[0-9a-zA-Z]+\\.com", email)) {
////            return "邮箱格式有误";
////        }
        return YConstant.SUCCESS;
    }
}
